/*
 * StatusUnit class handles machine status and machine fault information. 
 * 
 * The Status Unit is composed of the Machine Status Register and 
 * the Machine Fault Register.  
 * 
 * There are no dedicated operations associated with the Status Unit.
 * */

package cpu.components;

import cpu.datastores.Register1;
import cpu.datastores.Register16;
import cpu.datastores.Register4;

public class StatusUnit {
	// Machine Status Register
	public Register16 MSR;

	//Machine Fault Register
	public Register4 MFR;
	
	public Register1 BOOT;
	public Register1 STOP;
	public Register1 EXIT;
	public Register1 STEP;
	
	// Reference to the cpu to access machine state for status reporting.
	private cpu.components.CPU cpu;
	
	public StatusUnit( cpu.components.CPU cpu ) {
		this.cpu = cpu;
		
		MSR = new Register16( );
		MFR = new Register4( );
		
		STOP = new Register1( );
		EXIT = new Register1( );
		BOOT = new Register1( );
		STEP = new Register1( );

	}
	
	public void fault( ) {
		// Trap to the second memory address for fault handler
		
		// Status 1 = Faulted
		cpu.statusunit.MSR.fromJavaInt( 1 );
		cpu.controlunit.updateMachineStatusIndicator( );

		// MAR <- 2
		cpu.memoryunit.MAR.fromSignedInteger( 2 );
		cpu.controlunit.updateMemoryAddressIndicator( );
		
		// Memory( get )
		cpu.memoryunit.get( );
		
		// PC <- MBR
		cpu.controlunit.PC.fromRegister( cpu.memoryunit.MBR );
		cpu.controlunit.updateProgramCounterIndicator( );
		
	}
}
